package com.td.client.gui;

import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;

import com.td.client.log.GameplayInfo;
import com.td.core.communication.obj.PreGameInfo;
import com.td.core.obj.TDMap;
import com.td.core.obj.tower.Tower;

public class AdditivesRenderer implements TDMap.DrawParams {

	public static void draw(GameplayInfo gameplayInfo, PreGameInfo preGameInfo, Graphics g) {
		
		float x = preGameInfo.getMyPlayer().getNumber() * BSIZE_X + BREAK;
		x -= GameRenderer.getInstance().getBaseX();
		
		//miejsce do stawiania wiezyczek
		g.setColor(Color.white);
		float rx = x;
		float ry = TDMap.UP_BUFFOR * FIELD_SIZE;
		float rsx = SIZE_X;
		float rsy = TDMap.BLD_Y * FIELD_SIZE;
		g.drawRect(rx, ry, rsx, rsy);
		
		if(gameplayInfo.isNet()) {
					
			g.setColor(Color.gray);
			//TODO
			//do poprawki - tymczasowo
//			for(int i = TDMap.UP_BUFFOR ; i < (TDMap.SIZE_Y - TDMap.DOWN_BUFFOR - 3) / SCALE ; i ++)
//				g.drawLine(x, MapRenderer.BASE_Y +  i * SCALE, x + TDMap.SIZE_X, MapRenderer.BASE_Y + i * SCALE);
//							
//			for(int i = 0 ; i < TDMap.SIZE_X / SCALE ; i ++)
//				g.drawLine(x + i*SCALE, MapRenderer.BASE_Y + TDMap.UP_BUFFOR * SCALE , x + i *SCALE, MapRenderer.BASE_Y + TDMap.SIZE_Y - TDMap.DOWN_BUFFOR * SCALE);
		}
		
		Tower t = gameplayInfo.getAddingTower();
		if(t != null) {
			float tx = x + t.getPosition().getX() * FIELD_SIZE;
			float ty = t.getPosition().getY() * FIELD_SIZE;
			float ts = t.getSize() * FIELD_SIZE;
			
			if(gameplayInfo.isTowerAddOn()) {
				g.setColor(Color.green);
				float tr = t.getRange() * FIELD_SIZE;
				float t2r = 2*tr;
				g.drawOval(tx+ts/2-tr, ty+ts/2-tr, t2r, t2r);
			} else {
				g.setColor(Color.red);
			}
			
			g.fillRect(tx, ty, ts, ts);
		}
	}
}
